//https://zhuanlan.zhihu.com/p/22110802
var log4js = require('log4js');
log4js.configure({
    appenders: [
        {
            type: 'console'
        },
        {
            type: 'file',
            filename: 'default.log',
            pattern: '-yyyy-MM-dd.log',
            alwaysIncludePattern: true,
            category: 'default',
            maxLogSize: 1024 * 1024,
        }]
});
global.logger = log4js.getLogger("default");
logger.setLevel('all');

var obj = {
    "log": "debug",
    "debug": "debug",
    "error": "error",
    "exception": "error",
    "info": "info",
    "trace": "trace",
    "warn": "warn"
};

Object.keys(obj).forEach(function (key) {
    console.log("set console", key, obj[key]);
    console[key] = function (base, fun) {
        return function () {
            var array = Array.prototype.slice.apply(arguments);
            logger[fun].apply(logger, array);
            //array.unshift("[" + moment().format("YYYY-MM-DD hh:mm:ss SSS") + "]");
            //base.apply(this, array);
        }
    }(console[key], obj[key]);
})

// logger.log("Some debug messages");
// logger.debug("Some debug messages");
// logger.error("Some debug messages");
// logger.info("Some debug messages");
// logger.trace("Some debug messages");
// logger.warn("Some debug messages");
